package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.CartDao;
import com.foreknow.elm.dao.impl.CartDaoImpl;
import com.foreknow.elm.po.Cart;
import com.foreknow.elm.service.CartService;
import com.foreknow.elm.util.DBUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @author shkstart
 * @create 2021-08-26 17:18
 */
public class CartServiceImpl implements CartService {
    @Override
    public List<Object> listCart(String userId, int businessId) {
        CartDao dao=new CartDaoImpl();
        try {
            List<Object> list = dao.listCart(userId, businessId);
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }


        return null;
    }

    @Override
    public int saveCart(String userId, int businessId, int foodId) {
        CartDao dao=new CartDaoImpl();
        try {
            int i = dao.saveCart(userId, businessId, foodId);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }


        return 0;
    }

    @Override
    public int updateCart(String userId, int businessId, int foodId, int quantity) {
        CartDao dao=new CartDaoImpl();
        try {
            int i = dao.updateCart(userId, businessId, foodId, quantity);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int removeCart(Cart cart) {
        CartDao dao=new CartDaoImpl();
        try {
            int i = dao.removeCart(cart);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
